# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'login.ui'
#
# Created: Tue Jun 19 23:11:20 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from pl.edu.budgetanalizer.GUI import NewAccount
import pyodbc

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Form(QtGui.QWidget):
    login = ""
    haslo = ""
    
    def login(self):
        self.login = self.loginlineEdit.text()
        self.haslo = self.passLineEdit.text()
        
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        cur.execute("exec getUser ?",str(self.login))
        row = cur.fetchone()
        if row == None:
            raise Exception('Nie ma takiego uzytkownika')
        cur.execute("exec checkUser ?, ?",str(self.login),str(self.haslo))
        row = cur.fetchone()
        if row == None:
            raise Exception('Haslo niepoprawne')
        conn.close()
        
        self.BudgetAnalizer.login = self.login
        self.BudgetAnalizer.password = self.haslo
        
        self.Form.close()
        #autoryzacja
        
    def createAccount(self):
        self.accountWidget = NewAccount.Ui_Form(self.Form)
        self.accountWidget.setupUi(self.accountWidget,self.databaseDir,self.BudgetAnalizer)
        self.accountWidget.setGeometry(QtCore.QRect(0, 0, 461, 511))
        self.accountWidget.setAutoFillBackground(True)
        self.accountWidget.show()
        
    
    
    def setupUi(self, Form,databaseDir,BudgetAnalizer):
        self.BudgetAnalizer = BudgetAnalizer
        self.Form = Form
        self.databaseDir = databaseDir
        self.Form.setObjectName(_fromUtf8("Form"))
        self.Form.resize(400, 451)
        self.loginLabel = QtGui.QLabel(self.Form)
        self.loginLabel.setGeometry(QtCore.QRect(60, 90, 46, 13))
        self.loginLabel.setObjectName(_fromUtf8("loginLabel"))
        self.passLabel = QtGui.QLabel(Form)
        self.passLabel.setGeometry(QtCore.QRect(60, 120, 46, 13))
        self.passLabel.setObjectName(_fromUtf8("passLabel"))
        self.loginlineEdit = QtGui.QLineEdit(Form)
        self.loginlineEdit.setGeometry(QtCore.QRect(120, 90, 113, 20))
        self.loginlineEdit.setObjectName(_fromUtf8("loginlineEdit"))
        self.passLineEdit = QtGui.QLineEdit(Form)
        self.passLineEdit.setGeometry(QtCore.QRect(120, 110, 113, 20))
        self.passLineEdit.setObjectName(_fromUtf8("passLineEdit"))
        self.verticalLayoutWidget = QtGui.QWidget(Form)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(50, 170, 141, 81))
        self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
        self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.newAcconuButton = QtGui.QPushButton(self.verticalLayoutWidget)
        self.newAcconuButton.setMinimumSize(QtCore.QSize(0, 30))
        self.newAcconuButton.setObjectName(_fromUtf8("newAcconuButton"))
        self.newAcconuButton.connect(self.newAcconuButton, QtCore.SIGNAL("clicked()"), self.createAccount)
        self.verticalLayout.addWidget(self.newAcconuButton)
        self.loginButton = QtGui.QPushButton(Form)
        self.loginButton.setGeometry(QtCore.QRect(270, 90, 91, 30))
        self.loginButton.setMinimumSize(QtCore.QSize(30, 30))
        self.loginButton.setObjectName(_fromUtf8("loginButton"))
        self.loginButton.connect(self.loginButton, QtCore.SIGNAL("clicked()"), self.login)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.loginLabel.setText(QtGui.QApplication.translate("Form", "Login:", None, QtGui.QApplication.UnicodeUTF8))
        self.passLabel.setText(QtGui.QApplication.translate("Form", "Haslo:", None, QtGui.QApplication.UnicodeUTF8))
        self.newAcconuButton.setText(QtGui.QApplication.translate("Form", "Utworz nowe konto", None, QtGui.QApplication.UnicodeUTF8))
        self.loginButton.setText(QtGui.QApplication.translate("Form", "Zaloguj", None, QtGui.QApplication.UnicodeUTF8))

